package com.zlx.springclouddemo.gateway.zuul.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.zuul.filters.RefreshableRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.SimpleRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;

import java.util.LinkedHashMap;
import java.util.Map;

public class CustomRouteLocator extends SimpleRouteLocator implements RefreshableRouteLocator {

    private final static Logger logger = LoggerFactory.getLogger(CustomRouteLocator.class);

    private ZuulProperties zuulProperties;

    public CustomRouteLocator(String servletPath, ZuulProperties properties) {
        super(servletPath, properties);
        this.zuulProperties = properties;
        logger.info("servletPath:{}", servletPath);
    }

    @Override
    public void refresh() {
        doRefresh();
        logger.info("-----------------------------CustomRouteLocator refresh------------------------------------------------");
    }

    @Override
    protected Map<String, ZuulProperties.ZuulRoute> locateRoutes() {
        logger.info("-----------------------------CustomRouteLocator locateRoutes------------------------------------------------");
        LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>();
        routesMap.putAll(super.locateRoutes());
        return routesMap;
    }

}
